<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<link rel="STYLESHEET" href="lib.css" type='text/css' />
<link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" />
<link rel='start' href='../index.html' title='Python documentation Index' />
<link rel="first" href="lib.html" title='Python library Reference' />
<link rel='contents' href='contents.html' title="Contents" />
<link rel='index' href='genindex.html' title='Index' />
<link rel='last' href='about.html' title='About this document...' />
<link rel='help' href='about.html' title='About this document...' />
<link rel="next" href="module-encodings.utf-8-sig.html" />
<link rel="prev" href="standard-encodings.html" />
<link rel="parent" href="module-codecs.html" />
<link rel="next" href="module-encodings.utf-8-sig.html" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name='aesop' content='information' />
<title>4.8.4 encodings.idna -- Internationalized Domain Names in Applications</title>
</head>
<body>
<div class="navigation">
<div id='top-navigation-panel' xml:id='top-navigation-panel'>
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="4.8.3 standard Encodings"
  href="standard-encodings.html"><img src='../icons/previous.png'
  border='0' height='32'  alt='Previous Page' width='32' /></a></td>
<td class='online-navigation'><a rel="parent" title="4.8 codecs  "
  href="module-codecs.html"><img src='../icons/up.png'
  border='0' height='32'  alt='Up one Level' width='32' /></a></td>
<td class='online-navigation'><a rel="next" title="4.8.5 encodings.utf_8_sig  "
  href="module-encodings.utf-8-sig.html"><img src='../icons/next.png'
  border='0' height='32'  alt='Next Page' width='32' /></a></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
  href="contents.html"><img src='../icons/contents.png'
  border='0' height='32'  alt='Contents' width='32' /></a></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
  border='0' height='32'  alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index"
  href="genindex.html"><img src='../icons/index.png'
  border='0' height='32'  alt='Index' width='32' /></a></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="standard-encodings.html">4.8.3 Standard Encodings</a>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="module-codecs.html">4.8 codecs  </a>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="module-encodings.utf-8-sig.html">4.8.5 encodings.utf_8_sig  </a>
</div>
<hr /></div>
</div>
<!--End of Navigation Panel-->

<h2><a name="SECTION006840000000000000000">
4.8.4 <tt class="module">encodings.idna</tt> --
            Internationalized Domain Names in Applications</a>
</h2>

<p>
<a name="module-encodings.idna"></a>

<p>

<span class="versionnote">New in version 2.3.</span>

<p>
This module implements <a class="rfc" id='rfcref-98423' xml:id='rfcref-98423'
href="http://www.faqs.org/rfcs/rfc3490.html">RFC 3490</a> (Internationalized Domain Names in
Applications) and <a class="rfc" id='rfcref-98425' xml:id='rfcref-98425'
href="http://www.faqs.org/rfcs/rfc3492.html">RFC 3492</a> (Nameprep: A Stringprep Profile for
Internationalized Domain Names (IDN)). It builds upon the
<code>punycode</code> encoding and <tt class="module"><a href="module-stringprep.html">stringprep</a></tt>.

<p>
These RFCs together define a protocol to support non-ASCII characters
in domain names. A domain name containing non-ASCII characters (such
as ``www.Alliancefrançaise.nu'') is converted into an
ASCII-compatible encoding (ACE, such as
``www.xn-alliancefranaise-npb.nu''). The ACE form of the domain name
is then used in all places where arbitrary characters are not allowed
by the protocol, such as DNS queries, HTTP <span class="mailheader">Host:</span> fields, and so
on. This conversion is carried out in the application; if possible
invisible to the user: The application should transparently convert
Unicode domain labels to IDNA on the wire, and convert back ACE labels
to Unicode before presenting them to the user.

<p>
Python supports this conversion in several ways: The <code>idna</code> codec
allows to convert between Unicode and the ACE. Furthermore, the
<tt class="module"><a href="module-socket.html">socket</a></tt> module transparently converts Unicode host names to
ACE, so that applications need not be concerned about converting host
names themselves when they pass them to the socket module. On top of
that, modules that have host names as function parameters, such as
<tt class="module"><a href="module-httplib.html">httplib</a></tt> and <tt class="module"><a href="module-ftplib.html">ftplib</a></tt>, accept Unicode host names
(<tt class="module"><a href="module-httplib.html">httplib</a></tt> then also transparently sends an IDNA hostname in
the <span class="mailheader">Host:</span> field if it sends that field at all). 

<p>
When receiving host names from the wire (such as in reverse name
lookup), no automatic conversion to Unicode is performed: Applications
wishing to present such host names to the user should decode them to
Unicode.

<p>
The module <tt class="module">encodings.idna</tt> also implements the nameprep
procedure, which performs certain normalizations on host names, to
achieve case-insensitivity of international domain names, and to unify
similar characters. The nameprep functions can be used directly if
desired.

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-557' xml:id='l2h-557' class="function">nameprep</tt></b>(</nobr></td>
  <td><var>label</var>)</td></tr></table></dt>
<dd>
Return the nameprepped version of <var>label</var>. The implementation
currently assumes query strings, so <code>AllowUnassigned</code> is
true.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-558' xml:id='l2h-558' class="function">ToASCII</tt></b>(</nobr></td>
  <td><var>label</var>)</td></tr></table></dt>
<dd>
Convert a label to ASCII, as specified in <a class="rfc" id='rfcref-98427' xml:id='rfcref-98427'
href="http://www.faqs.org/rfcs/rfc3490.html">RFC 3490</a>.
<code>UseSTD3ASCIIRules</code> is assumed to be false.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-559' xml:id='l2h-559' class="function">ToUnicode</tt></b>(</nobr></td>
  <td><var>label</var>)</td></tr></table></dt>
<dd>
Convert a label to Unicode, as specified in <a class="rfc" id='rfcref-98429' xml:id='rfcref-98429'
href="http://www.faqs.org/rfcs/rfc3490.html">RFC 3490</a>.
</dl>

<p>

<div class="navigation">
<div class='online-navigation'>
<p></p><hr />
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="4.8.3 standard Encodings"
  href="standard-encodings.html"><img src='../icons/previous.png'
  border='0' height='32'  alt='Previous Page' width='32' /></a></td>
<td class='online-navigation'><a rel="parent" title="4.8 codecs  "
  href="module-codecs.html"><img src='../icons/up.png'
  border='0' height='32'  alt='Up one Level' width='32' /></a></td>
<td class='online-navigation'><a rel="next" title="4.8.5 encodings.utf_8_sig  "
  href="module-encodings.utf-8-sig.html"><img src='../icons/next.png'
  border='0' height='32'  alt='Next Page' width='32' /></a></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
  href="contents.html"><img src='../icons/contents.png'
  border='0' height='32'  alt='Contents' width='32' /></a></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
  border='0' height='32'  alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index"
  href="genindex.html"><img src='../icons/index.png'
  border='0' height='32'  alt='Index' width='32' /></a></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="standard-encodings.html">4.8.3 Standard Encodings</a>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="module-codecs.html">4.8 codecs  </a>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="module-encodings.utf-8-sig.html">4.8.5 encodings.utf_8_sig  </a>
</div>
</div>
<hr />
<span class="release-info">Release 2.5.1, documentation updated on 18th April, 2007.</span>
</div>
<!--End of Navigation Panel-->
<address>
See <i><a href="about.html">About this document...</a></i> for information on suggesting changes.
</address>
</body>
</html>
